import basegraphunit from './basegraphunit.js'
import coorPkg from '../../struct/coord.js'

class Polyline extends basegraphunit.BaseGraphUnit {
    constructor() {
        super();
        this.pos = new coorPkg.MultiPos();
        this.strPosition = "";
        this.close = false;
        this.symbolLeadwireFlag = false;
        this.visionType = 'cross';
    }

    translateSubInfo(tx,ty){
        this.strPosition = this.pos.toString();
    }
    
    toJson() {
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["strPosition"] = this.pos.toString();
        jsonobj["close"] = this.close;
        jsonobj["symbolLeadwireFlag"] = this.symbolLeadwireFlag;
        jsonobj["visionType"] = this.visionType;
        return jsonobj;
    }
    fromJson(obj) {
        super.fromJson(obj);
        var sx = obj["sx"];
        var sy = obj["sy"];
        if (sx != null && sy != null) {
            this.pos.setPosByString(sx, sy);
        }
        else {
            this.strPosition = obj["strPosition"];
            this.pos.fromString(this.strPosition);
        }
        this.close = obj["close"];
        this.symbolLeadwireFlag = obj["symbolLeadwireFlag"];
        this.visionType = obj["visionType"];
    }
    cloneCopy() {
        var pNewInfo = new Polyline();
        super.cloneCopy(pNewInfo);
        pNewInfo.close = this.close;
        pNewInfo.symbolLeadwireFlag = this.symbolLeadwireFlag;
        pNewInfo.visionType = this.visionType;
        return pNewInfo;
    }
}

export default { Polyline }